/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

 /***************************************************************************
 * Name: sys_utils.cpp
 *
 * Purpose: tool functions
 *
 * Developer:
 *   wen.gu , 2020-09-07
 *
 * TODO:
 *
 ***************************************************************************/

 /******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#include "panda/sys/sys_utils.h"

#include <chrono>
#include <thread>     


#include "panda/sys/property.h"

namespace panda
{
namespace sys
{
/******************************************************************************
 **    MACROS
 ******************************************************************************/
#define SYS_OS_VERSION      "ro.sys.version"
#define SYS_BUILD_DATE      "ro.sys.build_date"
#define SYS_BUILD_HOST      "ro.sys.build_host"
#define SYS_PRJ_NAME        "ro.sys.prj_name"
#define SYS_BUILD_TYPE      "ro.sys.build_type"
#define SYS_ROOT_DIR        "ro.sys.root_dir"
#define SYS_HOST_TYPE       "ro.sys.host"
#define SYS_PLATFORM_TYPE   "ro.sys.platform"

/******************************************************************************
 **    VARIABLE DEFINITIONS
 ******************************************************************************/



/******************************************************************************
 **    FUNCTION DEFINITIONS
 ******************************************************************************/
std::string GetHostType()
{
    std::string type;
    PropertyGet(SYS_HOST_TYPE, type);
    return type;
}

std::string GetPlatformType()
{
    std::string type;
    PropertyGet(SYS_PLATFORM_TYPE, type);
    return type;
}

std::string GetOsVersion()
{
    std::string type;
    PropertyGet(SYS_OS_VERSION, type);
    return type;
}

std::string GetBuildDate()
{
    std::string type;
    PropertyGet(SYS_BUILD_DATE, type);
    return type;
}

std::string GetBuildHost()
{
    std::string type;
    PropertyGet(SYS_BUILD_HOST, type);
    return type;
}

std::string GetProjectName()
{
    std::string type;
    PropertyGet(SYS_PRJ_NAME, type);
    return type;
}

std::string GetBuildType()
{
    std::string type;
    PropertyGet(SYS_BUILD_TYPE, type);
    return type;
}

std::string GetRootDir()
{
    std::string type;
    PropertyGet(SYS_ROOT_DIR, type);
    return type;
}

std::string GetPersistenceDir()
{
#if defined(_WIN32)
    return GetRootDir() + "var\\per\\";
#else
    return GetRootDir() + "var/per/";
#endif
}

std::string GetKvStorageDir()
{
#if defined(_WIN32)
    return GetRootDir() + "var\\per\\.kvstore\\";
#else
    return GetRootDir() + "var/per/.kvstore/";
#endif
}

std::string GetPacketInfoDir()
{
#if defined(_WIN32)
    return GetRootDir() + "var\\pkt_info\\";
#else
    return GetRootDir() + "var/pkt_info/";
#endif
}

std::string GetIconDir()
{
#if defined(_WIN32)
    return GetRootDir() + "var\\icons\\";
#else
    return GetRootDir() + "var/icons/";
#endif
}

std::string GetBinDir()
{
#if defined(_WIN32)
    return GetRootDir() + "bin\\";
#else
    return GetRootDir() + "bin/";
#endif
}

std::string GetLibDir()
{
#if defined(_WIN32)
    return GetRootDir() + "lib\\";
#else
    return GetRootDir() + "lib/";
#endif
}

std::string GetTmpDir()
{
#if defined(_WIN32)
    return GetRootDir() + "tmp\\";
#else
    return GetRootDir() + "tmp/";
#endif
}

std::string GetDownloadDir()
{
#if defined(_WIN32)
    return GetRootDir() + "download\\";
#else
    return GetRootDir() + "download/";
#endif
}

std::string GetExtraDir()
{
#if defined(_WIN32)
    return GetRootDir() + "extra\\";
#else
    return GetRootDir() + "extra/";
#endif
}

std::string GetUserDir()
{
#if defined(_WIN32)
    return GetRootDir() + "usr\\";
#else
    return GetRootDir() + "usr/";
#endif
}

std::string GetUserBinDir()
{
#if defined(_WIN32)
    return GetRootDir() + "usr\\bin\\";
#else
    return GetRootDir() + "usr/bin/";
#endif
}

std::string GetUserLibDir()
{
#if defined(_WIN32)
    return GetRootDir() + "usr\\lib\\";
#else
    return GetRootDir() + "usr/lib/";
#endif
}

std::string GetUserConfigDir()
{
#if defined(_WIN32)
    return GetRootDir() + "var\\etc\\";
#else
    return GetRootDir() + "var/etc/";
#endif
}

std::string GetDefaultPropertyFilePath()
{
#if defined(_WIN32)
    return  GetRootDir() + "\\etc\\prop\\default.prop";
#else
    return GetRootDir() + "/etc/prop/default.prop";
#endif
}

} /** namespace sys */
} /** namespace panda */
